//
//  BindingBankCardTableViewCell.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/6/17.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "BindingBankCardTableViewCell.h"

#define Margin 8

@implementation BindingBankCardTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpBindingBankCardCell];
    }
    return self;
}

- (void)setUpBindingBankCardCell {
    UILabel *label = [[UILabel alloc] init];
    label.textAlignment = NSTextAlignmentRight;
    label.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:label];
    self.leftLabel = label;
    
    UITextField *textField = [[UITextField alloc] init];
    textField.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:textField];
    self.rightTextField = textField;
    
    UIButton *button = [[UIButton alloc] init];
    [button setBackgroundColor:DEFAULT_COLOR];
    button.layer.cornerRadius = 5;
    button.hidden = YES;
    button.layer.masksToBounds = YES;
    
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button setTitle:@"获取验证码" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(didClickObtainButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.rightButton = button;
    [self addSubview:button];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).with.offset(Margin);
        make.width.mas_equalTo(self.width/3);
        make.height.mas_equalTo(self.Height);
    }];
    
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(label.mas_right).with.offset(Margin * 2);
        make.width.mas_equalTo(self.width/2);
        make.height.mas_equalTo(self.Height);
    }];

    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(textField.mas_centerY);
        make.right.equalTo(self.mas_right).with.offset(-Margin*2);
        make.width.mas_equalTo(self.width/4);
        make.height.mas_equalTo(self.Height/2 + 10);
    }];

}

- (void)didClickObtainButton:(UIButton *)button {
    
    if ([self.delegate respondsToSelector:@selector(didClickBindingBnakCardButton:)]) {
        [self.delegate didClickBindingBnakCardButton:button];
    }
    
}

@end
